package com.sk.seckilldemo.controller;

import com.sk.seckilldemo.entity.SeckillActivity;
import com.sk.seckilldemo.entity.request.SeckillRequest;
import com.sk.seckilldemo.mapper.SeckillActivityMapper;
import com.sk.seckilldemo.service.SeckillActivityService;
import com.sk.seckilldemo.service.SeckillService;
import com.sk.seckilldemo.util.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀功能API
 * */
@RestController
@CrossOrigin
@RequestMapping("/seckill")
@RequiredArgsConstructor
public class SeckillController {
    private final SeckillService seckillService;
    private final SeckillActivityService seckillActivityService;

    /**
     * 添加一个秒杀活动。
     * */
    @PostMapping("/addSeckillActivity")
    public Response addSeckillActivity(@RequestBody SeckillActivity seckillActivity){
        return seckillActivityService.insert(seckillActivity);
    }

    /**
     * 秒杀接口
     * 进行秒杀订单处理
     * */
    @PostMapping("/handleSeckill")
    public Response seckill(@RequestBody SeckillRequest seckillRequest){
        return seckillService.handleSeckill(seckillRequest);
    }


    /**
     * 预热接口：获取秒杀活动
     * */
    @PostMapping("/prepareSeckill")
    public Response prepare(@RequestBody SeckillRequest seckillRequest){
        seckillService.prepareSeckill(seckillRequest.getActivityId());
        return new Response(200,"秒杀活动预热成功",null);
    }
}
